import cv2 as cv
import numpy as ny


def trackbar_callback(value):
    print('value = ', value)

def median_blur():
    w_name = 'dst image'
    t_name = 'kernel'
    src_img = cv.imread('..//lena.png')
    cv.imshow('source image', src_img)
    cv.namedWindow(w_name, cv.WINDOW_AUTOSIZE)
    cv.createTrackbar(t_name, w_name, 5, 20, trackbar_callback)
    while 1:
        val = cv.getTrackbarPos(t_name, w_name)
        if val % 2:
            dst_image = cv.medianBlur(src_img, val)
            cv.imshow(w_name, dst_image)
        key = cv.waitKey(2)
        if key == 27:
            break


if __name__ == '__main__':
    median_blur()
